import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseGuards,
} from '@nestjs/common';
import { TagsService } from './tags.service';
import { CreateTagDto } from './dto/create-tag.dto';
import { UpdateTagDto } from './dto/update-tag.dto';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { GetUser } from '../common/decorators/get-user.decorator';
import { User } from '../users/entities/user.entity';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiBearerAuth,
} from '@nestjs/swagger';

@ApiTags('标签')
@Controller('tags')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
export class TagsController {
  constructor(private readonly tagsService: TagsService) {}

  @Post()
  @ApiOperation({ summary: '创建新标签' })
  @ApiResponse({ status: 201, description: '标签创建成功' })
  create(@Body() createTagDto: CreateTagDto, @GetUser() user: User) {
    return this.tagsService.create(createTagDto, user);
  }

  @Get()
  @ApiOperation({ summary: '获取所有标签' })
  @ApiResponse({ status: 200, description: '成功获取标签列表' })
  findAll(@GetUser() user: User) {
    return this.tagsService.findAll(user);
  }

  @Get(':id')
  @ApiOperation({ summary: '获取单个标签' })
  @ApiResponse({ status: 200, description: '成功获取标签' })
  @ApiResponse({ status: 404, description: '标签不存在' })
  findOne(@Param('id') id: string, @GetUser() user: User) {
    return this.tagsService.findOne(+id, user);
  }

  @Patch(':id')
  @ApiOperation({ summary: '更新标签' })
  @ApiResponse({ status: 200, description: '标签更新成功' })
  @ApiResponse({ status: 404, description: '标签不存在' })
  update(
    @Param('id') id: string,
    @Body() updateTagDto: UpdateTagDto,
    @GetUser() user: User,
  ) {
    return this.tagsService.update(+id, updateTagDto, user);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除标签' })
  @ApiResponse({ status: 200, description: '标签删除成功' })
  @ApiResponse({ status: 404, description: '标签不存在' })
  remove(@Param('id') id: string, @GetUser() user: User) {
    return this.tagsService.remove(+id, user);
  }
}
